package com.xiaoy.core.side.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.persistence.DynamicSpecifications;
import org.springside.modules.persistence.SearchFilter;

import com.xiaoy.core.side.dao.SideDao;
import com.xiaoy.core.side.dao.SideTypeDao;
import com.xiaoy.core.side.entity.Side;
import com.xiaoy.core.side.entity.SideType;
@Component
@Transactional
public class SideSerivce {

	@Autowired
	private SideDao sideDao;
	
	@Autowired
	private SideTypeDao sideTypeDao;
	
	public List<Side> search (Map<String, Object> searchParams) {
		
		System.out.println("sideDao-->"+sideDao);
		Map<String, SearchFilter> filters = SearchFilter.parse(searchParams);
		Specification<Side> spec = DynamicSpecifications.bySearchFilter(filters.values(), Side.class);
		List<Side> sideList = sideDao.findAll(spec);
		
		return sideList;
	}
	@Transactional
	public void save (Side side) {
		
		
		sideDao.save(side)	;
	}
	@Transactional
	public void saveType (SideType entity) {
		sideTypeDao.save(entity);
	}
	
	public List<SideType> getSideTypes () {
		return (List<SideType>) sideTypeDao.findAll();
	}
	
}
